package com.kwamecorp.brunoperry.kwamelogo.engine;

import android.opengl.Matrix;

import com.kwamecorp.brunoperry.kwamelogo.engine.math.Vector3D;

public class KCCamera3D {
	private float ratio;
	private float left;
	private float right;
	private float bottom;
	private float top;
	private float near;
	private float far;

	private float[] projectionMatrix = new float[16];
	private float[] viewMatrix = new float[16];
	private float[] perspective = new float[16];

	private Vector3D eye = new Vector3D();
	private Vector3D look = new Vector3D();
	private Vector3D up = new Vector3D();

	public KCCamera3D() {
	}

	public void init(float ratio, float left, float right, float bottom,
			float top, float near, float far) {
		this.ratio = ratio;
		this.left = left;
		this.right = right;
		this.bottom = bottom;
		this.top = top;
		this.near = near;
		this.far = far;
		Matrix.frustumM(projectionMatrix, 0, this.left, this.right,
				this.bottom, this.top, this.near, this.far);

		eye = new Vector3D(0.0f, 0.0f, 20f);
		look = new Vector3D(0.0f, 0.0f, -50.0f);
		up = new Vector3D(0.0f, 1.0f, 0.0f);
		Matrix.setLookAtM(viewMatrix, 0, eye.x, eye.y, eye.z, look.x, look.y,
				look.z, up.x, up.y, up.z);

		Matrix.perspectiveM(perspective, 0, 60.0f, this.ratio, this.near,
				this.far);
	}

	public void update() {
		Matrix.setLookAtM(viewMatrix, 0, eye.x, eye.y, eye.z, look.x, look.y,
				look.z, up.x, up.y, up.z);
	}

	public float[] getViewMatrix() {
		return viewMatrix;
	}

	public float[] getProjectionMatrix() {
		return projectionMatrix;
	}

	public void translate(Vector3D vector3d) {
		eye.x = vector3d.x;
		eye.y = vector3d.y;
		eye.z = vector3d.z;

	}
}
